/* 
 * File:   DecoderFactroy.cpp
 * Author: hao
 * 
 * Created on 2011年4月14日, 下午9:37
 */

#include "DecoderFactroy.h"
#include "Decoder.h"

DecoderFactroy::DecoderFactroy() {
}

int DecoderFactroy::addDecoder(const char* path){
    
    Decoder * pDecoder = new Decoder( path );
    
    if( !pDecoder->Init() ){
        delete pDecoder;
        return -1;
    }
    
    pvDecoder.push_back( pDecoder );
    
    return pvDecoder.size() - 1;
    
}

void DecoderFactroy::Destroy(){
    for( unsigned i = 0; i < pvDecoder.size(); i++ )
        delete pvDecoder[i];
    pvDecoder.clear();
}

Decoder * DecoderFactroy::getDecoder(unsigned index){

    if( index < pvDecoder.size() )
        return pvDecoder[ index ];

    return NULL;

}


DecoderFactroy::~DecoderFactroy() {
    Destroy();
}

